import MJCrequesting from "../index";
import MJCrequestingToast from "../other";
import { IAcount, userCondition, userAction, projectCondition } from "./type";
import qs from "qs";
import { AxiosResponse } from "axios";
enum LoginAPI {
  AccountLogin = "/login",
  AccountRegister = "/login/register",
  AccountGetUsers = "/login/user",
  AccountGetProjects = "/login/projects",
  vaertifyToken = "/login/vertifyToken",
}
const DEFAULT_HEADERS = {
  "Content-Type": "application/json",
};
const NONE_HEADERS = {
  "Content-Type": "none",
};
export function accountLoginRequest<T>(account: IAcount) {
  return MJCrequesting.request<T>({
    url: LoginAPI.AccountLogin,
    method: "POST",
    data: JSON.stringify(account),
    headers: DEFAULT_HEADERS,
  });
}
export function accountRegisterRequest(account: IAcount) {
  return MJCrequesting.request({
    url: LoginAPI.AccountRegister,
    method: "POST",
    data: JSON.stringify(account),
    headers: DEFAULT_HEADERS,
    isMessageToast: true,
  });
}

export function getUsers(
  userCondition: userCondition,
  action: userAction = "all"
) {
  return MJCrequesting.request({
    url: LoginAPI.AccountGetUsers + "?action=" + action,
    method: "GET",
    params: qs.stringify(userCondition),
    headers: DEFAULT_HEADERS,
  });
}

export function getProjects<T = AxiosResponse>(
  projectCondition: projectCondition,
  action: userAction = "all"
) {
  return MJCrequesting.request<T>({
    url: LoginAPI.AccountGetProjects + "?action=" + action,
    method: "GET",
    params: projectCondition,
    headers: DEFAULT_HEADERS,
  });
}
export function vertifyLogin<T>() {
  return MJCrequesting.request<T>({
    url: LoginAPI.vaertifyToken,
    method: "GET",
    headers: DEFAULT_HEADERS,
  });
}
